package com.project.service.impl;

import com.project.bean.StatisticsMonthBean;
import com.project.bean.StatisticsProductBean;
import com.project.mapper.IStatisticsProductMapper;
import com.project.service.IStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;

@Service
@Transactional
public class StatisticServiceImpl implements IStatisticsService {
    @Autowired
    private IStatisticsProductMapper statisticsProductMapper;

    @Override
    public  HashMap<String, List<StatisticsProductBean>> statisticsByProduct(LocalDate startDate, LocalDate endDate) {
        HashMap<String, List<StatisticsProductBean>> statisticsByProductMap = new HashMap<>();

        //按类别统计
        List<StatisticsProductBean> byKind = statisticsProductMapper.statisticsByKind(startDate, endDate);
        statisticsByProductMap.put("byKind",byKind);
        //按品牌、类别统计
        List<StatisticsProductBean> byBrandKind = statisticsProductMapper.statisticsByBrandKind(startDate, endDate);
        statisticsByProductMap.put("byBrandKind",byBrandKind);

        return statisticsByProductMap;

    }

    @Override
    public List<StatisticsMonthBean> statisticsByMonth(String year) {
        return statisticsProductMapper.statisticsByMonth(year);
    }

    @Override
    public List<String> getYears() {
        return statisticsProductMapper.getYears();
    }
}
